#pragma once
#include "cocos2d.h"

#define MAX_SAMPLES 1000
#define MAX_ZEROS 4

using namespace cocos2d;
class MainScene : public CCLayer
{
private:	
	enum CalibrationState
	{
		IDLE,
		UNCALIBRATED,
		CALIBRATE_CENTER,
		CALIBRATE_LEFT,
		CALIBRATE_RIGHT,
		CALIBRATED,
		READY
	};

	enum MovementState
	{
		MOVEMENT_IDLE,
		POSITIVE,
		NEGATIVE,
		STOPPED
	};

	s3eSocket* g_Sock;
	CCLabelBMFont* status;
	CCSprite* yellowMask;
	CCSprite* greenMask;
	
	bool started;	
	
	CalibrationState calibrationState;
	MovementState movementState;

	double staticax, staticay;
	double maxsax, maxsay;
	double x,y,rx,ry;
	double ax, ay;
	double prevax, prevay,rv,rprevv,rpreva;
	double leftx;
	double rightx;
	int64 prevt;
	int64 realprevt;

public:
	virtual bool init(); 
	virtual void reset(CCObject* sender);
	static int32 pauseCallback(void* systemData, void* userData);
	void calibrate(double ax, double ay, double az, int64 t);
	void position(double ax, double ay, double az, int64 t);
	void handle_position();
	//void rhandle_position();
	virtual void mainLoop(ccTime time);	
	virtual void debugLoop(ccTime time);
	LAYER_NODE_FUNC(MainScene);
};

